import propsType from 'prop-types'
import { TextField } from '@mui/material';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';

const MyDatePicker = (props) => {
  const { field, setFieldValue } = props
  return (
    <DatePicker
      {...field}
      {...props}
      onChange={(value) => {
        setFieldValue(field.name, value)
      }}
      renderInput={(params) => <TextField {...params} variant="filled"/>}
    />
  )
}

MyDatePicker.propTypes = {
  label: propsType.string,
  setFieldValue: propsType.func.isRequired,
  field: propsType.object.isRequired
}

MyDatePicker.defaultProps = {
  label: '选择时间'
}

export default MyDatePicker